﻿using System;
using System.Collections.Generic;

class SortArrayOfStrings
{
    static void Main()
    {
        Console.WriteLine("Enter the length of the array:");
        int arrayLength = int.Parse(Console.ReadLine());
        string[] arrayOfStrings = new string[arrayLength];
        for (int index = 0; index < arrayLength; index++)
        {
            Console.WriteLine("Enter element {0}", index);
            arrayOfStrings[index] = Console.ReadLine();
        }
        Console.WriteLine("Your array is:");
        for (int i = 0; i < arrayLength; i++)
        {
            Console.WriteLine(arrayOfStrings[i]);
        }
        QuickSort(arrayOfStrings, 0, arrayLength - 1);
        Console.WriteLine("The sorted array is:");
        for (int z = 0; z < arrayLength; z++)
        {
            Console.WriteLine(arrayOfStrings[z]);
        }
    }
    public static void QuickSort(string[] stringArray, int start, int end)
    {
        int i = start;
        int j = end;
        string middleOfString = stringArray[(start + end) / 2];
        while (i <= j)
        {
            while (stringArray[i].CompareTo(middleOfString) < 0)
            {
                i++;
            }
            while(stringArray[j].CompareTo(middleOfString) > 0)
            {
                j--;
            }
            if (i <= j)
            {
                string temp = stringArray[i];
                stringArray[i] = stringArray[j];
                stringArray[j] = temp;
                i++;
                j--;
            }
        }
        if (start < j)
        {
            QuickSort(stringArray, start, j);
        }
        if(i < end)
        {
            QuickSort(stringArray, i, end);
        }
        
    }
    


}

